//
//  DataBaseAccess.h
//  Wallets Manager
//
//  Created by Nguyen Chi Cong on 9/24/12.
//  Copyright (c) 2012 BKHN. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Attributes.h"

@interface DataBaseAccess : NSObject


//SAVE
+(BOOL)saveData;

//CREATE DATA
+(BOOL)createWalletWithName: (NSString *)name andBalance:(double)balance andDate: (NSDate *)date andDebt:(double)debt andLoan: (double) loan andPword:(NSString*)pword andImage: (NSString*) image;
+(BOOL)createWalletWithName: (NSString *)name andBalance:(double)balance andDate: (NSDate *)date andDebt:(double)debt andLoan: (double) loan andPword:(NSString*)pword andImage: (NSString*) image andDescrition: (NSString*)desc andCurrency: (id)typeCurrency;
+(BOOL)createWalletWithName: (NSString *)name andBalance: (double)balance andDate: (NSDate *)date andPword:(NSString*)pword andImage: (NSString*) image;
+(BOOL)createWalletWithName:(NSString *)name andBalance:(double)balance andCurrency:(Currency*)currency andDate:(NSDate *)date andPword:(NSString *)pword andDescription:(NSString*)description andImage:(NSString *)image;
+(BOOL)createPlanWithName: (NSString *)name andAmount: (double)amount andStartDate: (NSDate *)startDate andExpectedDate: (NSDate *)expectedDate inWallet: (id)wallet;
+(BOOL)createPlanWithName: (NSString *)name inWallet: (id)wallet;
+ (BOOL) createPlanWithName:(NSString *)name andAmount:(double)amount andstartAmout:(double)startAmount andImage:(NSString*)image inWallet:(id)wallet andIsCompleted : (BOOL)isCompleted;

+(void) initData;
+(BOOL)createIncomeWithname: (NSString *)name andAmount: (double) amount andDate: (NSDate *)date andNotes:(NSString *)notes inPlan: (id)plan ofType: (id)type;
+(BOOL)createExpenseWithname: (NSString *)name andAmount: (double) amount andDate: (NSDate *)date andNotes:(NSString *)notes inPlan: (id)plan ofType: (id)type;

+(BOOL)createDebtWithName: (NSString *)name andAmount: (double)amount andDate: (NSDate *)date andExpectedDate: (NSDate *)expectedDate andLender: (NSString *)lender andNotes: (NSString *)notes inWallet: (id)wallet;
+(BOOL)createLoanWithName: (NSString *)name andAmount: (double)amount andDate: (NSDate *)date andExpectedDate: (NSDate *)expectedDate andBorrower: (NSString *)borrower andNotes: (NSString *)notes inWallet: (id)wallet;

+(BOOL)createDebtHistory: (double)amount onDate: (NSDate *)date inDebt: (id)debt;
+(BOOL)createLoanHistory: (double)amount onDate: (NSDate *)date inLoan: (id)loan;

+(BOOL)createExpenseTypeWithName: (NSString *)name andImage: (NSString *)image;
+(BOOL)createIncomeTypeWithName: (NSString *)name andImage: (NSString *)image;

//QUERRY DATA
+(NSArray *)getAllWallet;
+(NSArray *)getAllIncomeType;
+(NSArray *)getAllCurrency;
+(NSArray *)getAllExpenseType;
+(NSArray *)getAllPlanInWallet: (id) wallet;
+(NSArray *)getAllLoanInWallet: (id) wallet;
+(NSArray *)getAllDebtInWallet: (id) wallet;
+(NSArray *)getAllDebtHistoryInDebt: (id)debt;
+(NSArray *)getAllLoanHistoryInLoan: (id)loan;
+(NSArray *)getAllIncomeInIncomeType: (id)incomeType;
+(NSArray *)getAllExpenseInExpenseType: (id)expenseType;
+(NSArray *)getAllIncomeInPlan: (id) plan;
+(NSArray *)getAllExpenseInPlan: (id) plan;
+ (NSArray*) getPlanByStatus : (Boolean)isCompleted andWallet : (Wallet *) wallet;

+(NSArray *)getAllIncomesInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;
+(NSArray *)getAllExpensesInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;

+(NSArray *)getAllIncomesOfType:(IncomeType *)ict inWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;
+(NSArray *)getAllExpensesOfType: (ExpenseType *)ett inWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;

+(NSDecimalNumber *)numberSumLoansinWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;
+(NSDecimalNumber *)numberSumDebtsinWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;


+(NSDecimalNumber *)numberSumIncomesinWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;
+(NSDecimalNumber *)numberSumExpensesinWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;

+(NSDecimalNumber *)numberSumIncomesInWallet: (id)wallet inMonth: (int)month andYear: (int)year;
+(NSDecimalNumber *)numberSumExpensesInWallet: (id)wallet inMonth: (int)month andYear: (int)year;

+(NSDecimalNumber *)numberSumIncomesOfType:(IncomeType *)ict inWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;

+(NSDecimalNumber *)numberSumExpensesOfType:(ExpenseType *)ett inWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to: (NSDate *)dateTo;

+(NSDecimalNumber *)numberSumIncomesOfType:(IncomeType *)ict inWallet: (id)wallet inMonth: (int)month andYear: (int)year;
+(NSDecimalNumber *)numberSumExpensesOfType:(IncomeType *)ict inWallet: (id)wallet inMonth: (int)month andYear: (int)year;

+(NSArray *)getAllDebtEventsInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;
+(NSArray *)getAllLoanEventsInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;

+(Loan *)maxLoanEventsInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;
+(Debt *)maxDebtEventsInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;
+(Income *)maxIncomeInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;
+(Expense *)maxExpenseInWallet: (id)wallet inTimeFrom: (NSDate *)dateFrom to:(NSDate *)dateTo;

+(NSMutableArray*)getAllIncomeDate:(id)wallet;
+(NSMutableArray*)getAllExpenseDate:(id)wallet;
+(NSMutableArray*)getAllDate:(id)wallet;
+(NSDictionary*) getIncomeAndExpenseByDate :(Wallet *)wallet;

+(NSMutableArray*) getAllIncomeByDate :(Wallet*)wallet andDate:(NSDate*)date;
+(NSMutableArray*) getAllExpenseByDate :(Wallet*)wallet andDate:(NSDate*)date;
+(NSMutableArray*) getAllLoanByDate :(Wallet*)wallet andDate:(NSDate*)date;
+(NSMutableArray*) getAllDebtByDate :(Wallet*)wallet andDate:(NSDate*)date;

+(NSMutableArray*) getAllIncomeByDate:(Wallet *)wallet andDateFrom:(NSDate*)dateFrom andDateTo:(NSDate*)dateTo;
+(NSMutableArray*) getAllExpenseByDate:(Wallet *)wallet andDateFrom:(NSDate*)dateFrom andDateTo:(NSDate*)dateTo;
+(NSMutableArray*) getAllLoanByDate:(Wallet *)wallet andDateFrom:(NSDate*)dateFrom andDateTo:(NSDate*)dateTo;
+(NSMutableArray*) getAllDebtByDate:(Wallet *)wallet andDateFrom:(NSDate*)dateFrom andDateTo:(NSDate*)dateTo;

+(NSMutableArray*) getAllIncomeByWallet :(Wallet*) wallet;
+(NSMutableArray*) getAllExpenseByWallet :(Wallet*) wallet;

+(Currency*)getCurrencyWithName:(NSString*)currencyName;

//ACTION

+(Plan *)planForName: (NSString *)pName;
+(Plan *)planForName: (NSString *)pName andWallet :(Wallet *) wallet;
+(ExpenseType *)eTypeForName: (NSString *)tName;
+(IncomeType *)iTypeForName: (NSString *)tName;
+(Wallet *)walletForName: (NSString *)wName;
+(Debt *)debtForName: (NSString *)dName;
+(Loan *)loanForName: (NSString *)lName;
+(Income *)incomeForName: (NSString *)iName;
+(Expense *)expenseForName: (NSString *)eName;
+(BOOL)movePlan: (NSString *)fromPlan toPlan: (NSString *)toPlan;
+(BOOL)movePlan:(NSString *)fromPlan toPlan:(NSString *)toNoPlan andWallet:(Wallet *) wallet;
+(BOOL)moveIncomType: (NSString *)itFrom to: (NSString *)itTo;
+(BOOL)moveExpenseType:(NSString *)etFrom to: (NSString *)etTo;


//CHECK
+(BOOL)checkExistPlan: (NSString *)pName;
+(BOOL)checkExistWallet: (NSString *)wName;
+(BOOL)checkExistDebt: (NSString *)dName;
+(BOOL)checkExistLoan: (NSString *)lName;
+(BOOL)checkExistIncome: (NSString *)iName;
+(BOOL)checkExistExpense: (NSString *)eName;
+(BOOL)checkExistIncomeType: (NSString *)itName;
+(BOOL)checkExistExpenseType: (NSString *)etName;

//SUMMARY



//DELETE OBJECT
+(void)deleteObject: (id)object;
+(void)deleteArrayObject: (NSArray *)listObject;
+(void)deleteLoanHistory:(LoanHistory *)hObject;
+(void)deleteDebtHistory:(DebtHistory *)hObject;
+(void)deleteDebt: (Debt *)dObject;
+(void)deleteLoan: (Loan *)lObject;
+(void)deleteIncome: (Income *)iObject;
+(void)deleteExpense: (Expense *)eObject;
+(void)deletePlan: (Plan *)pObject;
+(void)deleteWallet: (Wallet *) wObject;
+(void)deleteIncomeType:(IncomeType *)itObject;
+(void)deleteExpenseType: (ExpenseType *)etObject;


@end
